from django.db import models
from django.contrib.auth.models import User
from django.conf import settings


class User(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=50)


class qClass(models.Model):
    q_class = models.CharField('项目分类', max_length=20)

    def __str__(self):
        return str(self.q_class)

    class Meta:
        ordering = ('pk',)
        verbose_name_plural = '项目分类'


class qaWatch(models.Model):
    A_STATUS = (
        ('0', '未修复'),
        ('1', '修复中'),
        ('2', '测试中'),
        ('3', '修复完毕'),
        ('4', '无法修复')
    )
    Q_LEVEL = (
        ('0', '可推迟'),
        ('1', '优先修复'),
        ('2', '紧急修复'),
        ('3', '立刻修复'),
    )
    Q_CHECKOUT = (
        ('0', '未测试'),
        ('1', '通过'),
        ('2', '未通过'),
    )
    q_user = models.CharField('测试人', max_length=20)
    q_timer = models.DateTimeField('时间')
    q_content = models.TextField('问题内容')
    q_level = models.CharField('紧急程度', max_length=1, choices=Q_LEVEL, default='0')
    q_status = models.CharField('状态', max_length=1, choices=A_STATUS, default='0')
    a_user = models.CharField('修复人', max_length=20, blank=True, default='')
    a_timer = models.DateTimeField('修复时间', blank=True, null=True)
    q_backUp = models.TextField('备注', blank=True)
    q_class = models.ForeignKey(qClass, blank=True, null=True, on_delete=models.CASCADE, default='暂无分类')   # 外键,自动关联表的主键 级联删除
    q_checkOut = models.CharField('测试状态', max_length=1, choices=Q_CHECKOUT, default='0')
    # pub_date = models.DateTimeField('发表时间', auto_now_add=True, editable=True)
    # update_time = models.DateTimeField('更新时间', auto_now=True, null=True)

    def __str__(self):  # 在Python3中用 __str__ 代替 __unicode__
        return str(self.q_user) + str(self.q_class)

    class Meta:
        ordering = ('pk',)
        verbose_name_plural = '问题列表'